<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="../../css/weui.min.css" />
    <link rel="stylesheet" type="text/css" href="../../css/jquery-weui.min.css" />
    <link rel="stylesheet" type="text/css" href="../../css/index.css" />
    <link rel="stylesheet" type="text/css" href="../../css/mine.css" />
    <link rel="stylesheet" type="text/css" href="https://at.alicdn.com/t/font_546019_o8qxm6fupb0ggb9.css" />
    <title>新增物料</title>
    <script src="../../js/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/jquery-weui.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/baseConfig.js" type="text/javascript" charset="utf-8"></script>
</head>

<body>
    <!--<div id="header">
			<div class="header-title" style="position: fixed;top: 0;">
				<img src="../../img/left.png" class="left" />
				<span>新增物料</span>
			</div>
		</div>-->
    <div class="mine-content" style="margin-bottom: 0;margin-top: 0;">
        <!--过磅列表 -->
        <div class="name  select-type">
            <span>订单编号</span>
            <i class="iconfont icon-sanjiaodown vebdorIcon"></i>
            <input type="text" class="vebdor-type" disabled="disabled" placeholder="请选择订单" />
            <ul class="name_ul person_type">

            </ul>
        </div>
        <div class=" name select-type">
            <span>物料名称</span>
            <em class="em"><i class="iconfont icon-sanjiaodown documentIcon"></i></em>
            <input type="text" class="document-type" disabled="disabled" placeholder="请选择物料名称" />

        </div>
        <div class="name" style="border-bottom: none;">
            <span>装车重量</span>
            <input type="number" name="number" pattern="[0-9]*" class="company-phone" placeholder="请填写装车重量" /> 吨
        </div>
        <div class="demos-content-padded" style="margin-top: 1.5rem;">
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default default" style="float: left;background: #e5e5e5;">取消</a>
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary confirm" style="float: right;margin-top: 0;background: #28c81e;">确定</a>
            <!--<a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary delete" style="float: right;margin-top: 0;background: #f65555;margin-top: 20px;">删除</a>-->
        </div>
    </div>

</body>
<script type="text/javascript">
    $(document).ready(function() {
        baseConfig.historyBack()
            //			var carNo = baseConfig.GetQueryString("carNo");
            //			var orderNo = baseConfig.GetQueryString("orderNo");

        function GetQueryString(name) { //页面取值方法
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return decodeURI(r[2]);
            return null;
        }
        var voId = GetQueryString("voId") //物料id
        var id = GetQueryString("id")
        var orderNo = GetQueryString("orderNo") //订单号
        var carNo = GetQueryString("carNo"); //车牌号
        var driver = GetQueryString("driver"); //司机姓名
        var phone = GetQueryString("phone"); //司机电话
        var uploadTime = GetQueryString("uploadTime"); //装车时间
        var idCard = GetQueryString("idCard"); //司机身份证
        var planTime = GetQueryString("planTime"); //预计到达时间
        var weight = GetQueryString("weight"); //装车物料总重量


        //0表示是新增，1表示修改
        $.showLoading("加载中...");
        if (!orderNo) {

        } else {
            $(".vebdor-type").val(orderNo)
            picker(orderNo)
        }


        function picker(orderNo) {
            $.ajax({
                type: "get",
                url: baseConfig.localHttp + "weChatApi/fgclient/getGoodsNameList",
                async: false,
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                data: {
                    orderNo: orderNo
                },
                success: function(data) {
                    console.log(data)
                    var Data = data.content
                    var temp = [];
                    for (var i = 0; i < Data.length; i++) {
                        temp.push(Data[i].goodsName)
                    }
                    if (data.code == 100) {
                        $(".documentIcon").picker({
                            title: "请选择物料名称",
                            cols: [{
                                textAlign: 'center',
                                values: temp
                            }],
                            onClose: function(e) {
                                $(".document-type").val(e.value[0])
                                    //									console.log(e)
                                var index = e.cols[0].activeIndex
                                var goodsNo = Data[index].goodsNo
                                sessionStorage.setItem("goodsNo", goodsNo)
                            }

                        })
                    } else {
                        $.toptip(data.content, 1200, 'error');
                    }
                },
                error: function() {
                    $.hideLoading();
                    $.toptip(data.content, 1200, 'error');
                    //						$.toast("请求失败", "cancel");
                }
            })
        }

        //查订单列表
        $.ajax({
            type: "get",
            url: baseConfig.localHttp + "weChatApi/fgclient/getOrderNoList",
            async: false,
            data: {
                clientId: baseConfig.login()
            },
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            success: function(data) {
                $.hideLoading();
                console.log(data)
                var $li = "";
                if (data.code == 100) {
                    var content = data.content
                    if (content.length == 1) {
                        $('.vebdor-type').val(content[0])
                        picker(content[0])
                    } else {
                        for (var i = 0; i < content.length; i++) {
                            $li += "<li><b>" + content[i] + "</b></li>"
                        }
                        $(".person_type").append($li);
                        $(".person_type li").eq(0).attr("class", "active");
                        for (var j = 0; j < $(".person_type li").length; j++) {
                            $(".person_type li").eq(j).on("click", function() {
                                var value = $(this).find('b').html()
                                console.log(value)
                                $(this).parents(".name").find("input").val(value)
                                $(this).parents(".name").find(".icon-sanjiaodown").removeClass('active');
                                $(this).parents(".name").find(".icon-sanjiaodown").css("color", "#000")
                                $(this).addClass("active").siblings().removeClass("active")
                                $(this).parents(".name").find(".name_ul").slideUp()
                                $(".document-type").val("")
                                $(".em").empty()
                                $(".em").html("<i class='iconfont icon-sanjiaodown documentIcon'>")
                                sessionStorage.removeItem("goodsNo")
                                picker(value)
                            })
                        }
                        //订单编号点击切换效果
                        $(".vebdorIcon").on("click", function() {
                            var flag = $(this).hasClass('active');
                            if (!flag) {
                                $(this).addClass('active');
                                $(this).css("color", "#28C81E");
                                $(this).parents(".name").find(".name_ul").slideDown();
                            } else {
                                $(this).removeClass('active');
                                $(this).css("color", "#000");
                                $(this).parents(".name").find(".name_ul").slideUp()
                            }
                        })
                    }

                } else {
                    $.toptip(data.content, 1200, 'error');
                }
            },
            error: function() {
                $.hideLoading();
                $.toast("请求失败", "cancel");
            }
        })

        //点击确认，判断数据是否填写完整，然后跳转回上一个页面
        $('.confirm').on("click", function() {
                var orderNumber = $(".vebdor-type").val();
                var materialName = $(".document-type").val();
                var weight = $(".company-phone").val();
                $.ajax({
                    type: "get",
                    url: baseConfig.localHttp + "weChatApi/fgclient/addTranGoods",
                    async: false,
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                    data: {
                        goodsName: materialName,
                        goodsWeight: weight,
                        orderNo: orderNumber,
                        carNo: carNo,
                        goodsNo: sessionStorage.getItem("goodsNo"),
                        driver: driver,
                        phone: phone,
                        uploadTime: uploadTime,
                        idCard: idCard,
                        planTime: planTime,
                        id: id,
                        voId: voId
                    },
                    success: function(data) {
                        console.log(data)
                        if (data.code == 100) {
                            location.href = "addTransport.html?orderNo=" + orderNumber + "&carNo=" + carNo
                        } else {
                            $.toptip(data.content, 1200, 'error');
                        }
                    }
                })
            })
            //点击取消回到我的页面
        $(".default").on("click", function() {
            history.back()
        })
    })
</script>

</html>